<?php


abstract class BaseLypoStatement extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $text;


	
	protected $for_registration;


	
	protected $youtube_code;


	
	protected $vimeo_code;


	
	protected $dailymotion_code;


	
	protected $reaction_count = 0;


	
	protected $num_respects = 0;


	
	protected $sortorder;

	
	protected $collStatementAnswers;

	
	protected $lastStatementAnswerCriteria = null;

	
	protected $collStatementDays;

	
	protected $lastStatementDayCriteria = null;

	
	protected $collReactions;

	
	protected $lastReactionCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getText()
	{

		return $this->text;
	}

	
	public function getForRegistration()
	{

		return $this->for_registration;
	}

	
	public function getYoutubeCode()
	{

		return $this->youtube_code;
	}

	
	public function getVimeoCode()
	{

		return $this->vimeo_code;
	}

	
	public function getDailymotionCode()
	{

		return $this->dailymotion_code;
	}

	
	public function getReactionCount()
	{

		return $this->reaction_count;
	}

	
	public function getNumRespects()
	{

		return $this->num_respects;
	}

	
	public function getSortorder()
	{

		return $this->sortorder;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = LypoStatementPeer::ID;
		}

	} 
	
	public function setText($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->text !== $v) {
			$this->text = $v;
			$this->modifiedColumns[] = LypoStatementPeer::TEXT;
		}

	} 
	
	public function setForRegistration($v)
	{

		if ($this->for_registration !== $v) {
			$this->for_registration = $v;
			$this->modifiedColumns[] = LypoStatementPeer::FOR_REGISTRATION;
		}

	} 
	
	public function setYoutubeCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->youtube_code !== $v) {
			$this->youtube_code = $v;
			$this->modifiedColumns[] = LypoStatementPeer::YOUTUBE_CODE;
		}

	} 
	
	public function setVimeoCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->vimeo_code !== $v) {
			$this->vimeo_code = $v;
			$this->modifiedColumns[] = LypoStatementPeer::VIMEO_CODE;
		}

	} 
	
	public function setDailymotionCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->dailymotion_code !== $v) {
			$this->dailymotion_code = $v;
			$this->modifiedColumns[] = LypoStatementPeer::DAILYMOTION_CODE;
		}

	} 
	
	public function setReactionCount($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->reaction_count !== $v || $v === 0) {
			$this->reaction_count = $v;
			$this->modifiedColumns[] = LypoStatementPeer::REACTION_COUNT;
		}

	} 
	
	public function setNumRespects($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->num_respects !== $v || $v === 0) {
			$this->num_respects = $v;
			$this->modifiedColumns[] = LypoStatementPeer::NUM_RESPECTS;
		}

	} 
	
	public function setSortorder($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->sortorder !== $v) {
			$this->sortorder = $v;
			$this->modifiedColumns[] = LypoStatementPeer::SORTORDER;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->text = $rs->getString($startcol + 1);

			$this->for_registration = $rs->getBoolean($startcol + 2);

			$this->youtube_code = $rs->getString($startcol + 3);

			$this->vimeo_code = $rs->getString($startcol + 4);

			$this->dailymotion_code = $rs->getString($startcol + 5);

			$this->reaction_count = $rs->getInt($startcol + 6);

			$this->num_respects = $rs->getInt($startcol + 7);

			$this->sortorder = $rs->getInt($startcol + 8);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 9; 
		} catch (Exception $e) {
			throw new PropelException("Error populating LypoStatement object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(LypoStatementPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			LypoStatementPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(LypoStatementPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = LypoStatementPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += LypoStatementPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collStatementAnswers !== null) {
				foreach($this->collStatementAnswers as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collStatementDays !== null) {
				foreach($this->collStatementDays as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collReactions !== null) {
				foreach($this->collReactions as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = LypoStatementPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collStatementAnswers !== null) {
					foreach($this->collStatementAnswers as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collStatementDays !== null) {
					foreach($this->collStatementDays as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collReactions !== null) {
					foreach($this->collReactions as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = LypoStatementPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getText();
				break;
			case 2:
				return $this->getForRegistration();
				break;
			case 3:
				return $this->getYoutubeCode();
				break;
			case 4:
				return $this->getVimeoCode();
				break;
			case 5:
				return $this->getDailymotionCode();
				break;
			case 6:
				return $this->getReactionCount();
				break;
			case 7:
				return $this->getNumRespects();
				break;
			case 8:
				return $this->getSortorder();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = LypoStatementPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getText(),
			$keys[2] => $this->getForRegistration(),
			$keys[3] => $this->getYoutubeCode(),
			$keys[4] => $this->getVimeoCode(),
			$keys[5] => $this->getDailymotionCode(),
			$keys[6] => $this->getReactionCount(),
			$keys[7] => $this->getNumRespects(),
			$keys[8] => $this->getSortorder(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = LypoStatementPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setText($value);
				break;
			case 2:
				$this->setForRegistration($value);
				break;
			case 3:
				$this->setYoutubeCode($value);
				break;
			case 4:
				$this->setVimeoCode($value);
				break;
			case 5:
				$this->setDailymotionCode($value);
				break;
			case 6:
				$this->setReactionCount($value);
				break;
			case 7:
				$this->setNumRespects($value);
				break;
			case 8:
				$this->setSortorder($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = LypoStatementPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setText($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setForRegistration($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setYoutubeCode($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setVimeoCode($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setDailymotionCode($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setReactionCount($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setNumRespects($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setSortorder($arr[$keys[8]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(LypoStatementPeer::DATABASE_NAME);

		if ($this->isColumnModified(LypoStatementPeer::ID)) $criteria->add(LypoStatementPeer::ID, $this->id);
		if ($this->isColumnModified(LypoStatementPeer::TEXT)) $criteria->add(LypoStatementPeer::TEXT, $this->text);
		if ($this->isColumnModified(LypoStatementPeer::FOR_REGISTRATION)) $criteria->add(LypoStatementPeer::FOR_REGISTRATION, $this->for_registration);
		if ($this->isColumnModified(LypoStatementPeer::YOUTUBE_CODE)) $criteria->add(LypoStatementPeer::YOUTUBE_CODE, $this->youtube_code);
		if ($this->isColumnModified(LypoStatementPeer::VIMEO_CODE)) $criteria->add(LypoStatementPeer::VIMEO_CODE, $this->vimeo_code);
		if ($this->isColumnModified(LypoStatementPeer::DAILYMOTION_CODE)) $criteria->add(LypoStatementPeer::DAILYMOTION_CODE, $this->dailymotion_code);
		if ($this->isColumnModified(LypoStatementPeer::REACTION_COUNT)) $criteria->add(LypoStatementPeer::REACTION_COUNT, $this->reaction_count);
		if ($this->isColumnModified(LypoStatementPeer::NUM_RESPECTS)) $criteria->add(LypoStatementPeer::NUM_RESPECTS, $this->num_respects);
		if ($this->isColumnModified(LypoStatementPeer::SORTORDER)) $criteria->add(LypoStatementPeer::SORTORDER, $this->sortorder);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(LypoStatementPeer::DATABASE_NAME);

		$criteria->add(LypoStatementPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setText($this->text);

		$copyObj->setForRegistration($this->for_registration);

		$copyObj->setYoutubeCode($this->youtube_code);

		$copyObj->setVimeoCode($this->vimeo_code);

		$copyObj->setDailymotionCode($this->dailymotion_code);

		$copyObj->setReactionCount($this->reaction_count);

		$copyObj->setNumRespects($this->num_respects);

		$copyObj->setSortorder($this->sortorder);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getStatementAnswers() as $relObj) {
				$copyObj->addStatementAnswer($relObj->copy($deepCopy));
			}

			foreach($this->getStatementDays() as $relObj) {
				$copyObj->addStatementDay($relObj->copy($deepCopy));
			}

			foreach($this->getReactions() as $relObj) {
				$copyObj->addReaction($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new LypoStatementPeer();
		}
		return self::$peer;
	}

	
	public function initStatementAnswers()
	{
		if ($this->collStatementAnswers === null) {
			$this->collStatementAnswers = array();
		}
	}

	
	public function getStatementAnswers($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStatementAnswers === null) {
			if ($this->isNew()) {
			   $this->collStatementAnswers = array();
			} else {

				$criteria->add(StatementAnswerPeer::STATEMENT_ID, $this->getId());

				StatementAnswerPeer::addSelectColumns($criteria);
				$this->collStatementAnswers = StatementAnswerPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(StatementAnswerPeer::STATEMENT_ID, $this->getId());

				StatementAnswerPeer::addSelectColumns($criteria);
				if (!isset($this->lastStatementAnswerCriteria) || !$this->lastStatementAnswerCriteria->equals($criteria)) {
					$this->collStatementAnswers = StatementAnswerPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastStatementAnswerCriteria = $criteria;
		return $this->collStatementAnswers;
	}

	
	public function countStatementAnswers($criteria = null, $distinct = false, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(StatementAnswerPeer::STATEMENT_ID, $this->getId());

		return StatementAnswerPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addStatementAnswer(StatementAnswer $l)
	{
		$this->collStatementAnswers[] = $l;
		$l->setLypoStatement($this);
	}


	
	public function getStatementAnswersJoinUser($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStatementAnswers === null) {
			if ($this->isNew()) {
				$this->collStatementAnswers = array();
			} else {

				$criteria->add(StatementAnswerPeer::STATEMENT_ID, $this->getId());

				$this->collStatementAnswers = StatementAnswerPeer::doSelectJoinUser($criteria, $con);
			}
		} else {
									
			$criteria->add(StatementAnswerPeer::STATEMENT_ID, $this->getId());

			if (!isset($this->lastStatementAnswerCriteria) || !$this->lastStatementAnswerCriteria->equals($criteria)) {
				$this->collStatementAnswers = StatementAnswerPeer::doSelectJoinUser($criteria, $con);
			}
		}
		$this->lastStatementAnswerCriteria = $criteria;

		return $this->collStatementAnswers;
	}

	
	public function initStatementDays()
	{
		if ($this->collStatementDays === null) {
			$this->collStatementDays = array();
		}
	}

	
	public function getStatementDays($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStatementDays === null) {
			if ($this->isNew()) {
			   $this->collStatementDays = array();
			} else {

				$criteria->add(StatementDayPeer::STATEMENT_ID, $this->getId());

				StatementDayPeer::addSelectColumns($criteria);
				$this->collStatementDays = StatementDayPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(StatementDayPeer::STATEMENT_ID, $this->getId());

				StatementDayPeer::addSelectColumns($criteria);
				if (!isset($this->lastStatementDayCriteria) || !$this->lastStatementDayCriteria->equals($criteria)) {
					$this->collStatementDays = StatementDayPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastStatementDayCriteria = $criteria;
		return $this->collStatementDays;
	}

	
	public function countStatementDays($criteria = null, $distinct = false, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(StatementDayPeer::STATEMENT_ID, $this->getId());

		return StatementDayPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addStatementDay(StatementDay $l)
	{
		$this->collStatementDays[] = $l;
		$l->setLypoStatement($this);
	}

	
	public function initReactions()
	{
		if ($this->collReactions === null) {
			$this->collReactions = array();
		}
	}

	
	public function getReactions($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collReactions === null) {
			if ($this->isNew()) {
			   $this->collReactions = array();
			} else {

				$criteria->add(ReactionPeer::STATEMENT_ID, $this->getId());

				ReactionPeer::addSelectColumns($criteria);
				$this->collReactions = ReactionPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ReactionPeer::STATEMENT_ID, $this->getId());

				ReactionPeer::addSelectColumns($criteria);
				if (!isset($this->lastReactionCriteria) || !$this->lastReactionCriteria->equals($criteria)) {
					$this->collReactions = ReactionPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastReactionCriteria = $criteria;
		return $this->collReactions;
	}

	
	public function countReactions($criteria = null, $distinct = false, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(ReactionPeer::STATEMENT_ID, $this->getId());

		return ReactionPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addReaction(Reaction $l)
	{
		$this->collReactions[] = $l;
		$l->setLypoStatement($this);
	}


	
	public function getReactionsJoinUser($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collReactions === null) {
			if ($this->isNew()) {
				$this->collReactions = array();
			} else {

				$criteria->add(ReactionPeer::STATEMENT_ID, $this->getId());

				$this->collReactions = ReactionPeer::doSelectJoinUser($criteria, $con);
			}
		} else {
									
			$criteria->add(ReactionPeer::STATEMENT_ID, $this->getId());

			if (!isset($this->lastReactionCriteria) || !$this->lastReactionCriteria->equals($criteria)) {
				$this->collReactions = ReactionPeer::doSelectJoinUser($criteria, $con);
			}
		}
		$this->lastReactionCriteria = $criteria;

		return $this->collReactions;
	}

} 